﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Globalization;

using Katamino.Model.Data;

namespace Katamino
{
    // Data related stuff of the Penta class
    // This includes the constructors and the data access layer for persistent storage
    public class PentaData
    {
        public string ID;
        public int[] x;
        public int[] y;
        public Penta[] variations;
        public System.Drawing.Rectangle box;

        public void SetID(string groupID, int variationNumber)
        {
            ID = groupID + variationNumber.ToString();
        }

        public PentaData()
        {
            ID = "";
            x = new int[5];
            y = new int[5];
            variations = new Penta[0];
        }

        public PentaData(int[] _x, int[] _y)
        {
            ID = "";
            x = _x;
            y = _y;
            // variations to be filled in later
        }

        public PentaData debug()
        {
            Debug.WriteLine("");
            for (int i = 0; i < 5; i++)
            {
                Debug.WriteLine(x[i].ToString(CultureInfo.CurrentCulture) + "," + y[i].ToString(CultureInfo.CurrentCulture));
            }
            return this;
        }


        internal static KataminoDataSet.PentaDataTable GetCalculatedPentasForProblem(KataminoProblem problem)
        {
            var table = new KataminoDataSet.PentaDataTable();

            Task<KataminoDataSet.PentaDataTable>[] taskArray =
                new Task<KataminoDataSet.PentaDataTable>[]
                    {
                        /*
                        Task.Factory.StartNew(() => GetPentasType1(problem)),
                        Task.Factory.StartNew(() => GetPentasType2(problem)),
                        Task.Factory.StartNew(() => GetPentasType3(problem)),
                        Task.Factory.StartNew(() => GetPentasType4(problem)),
                        Task.Factory.StartNew(() => GetPentasType5(problem)),
                        Task.Factory.StartNew(() => GetPentasType6(problem)),
                        Task.Factory.StartNew(() => GetPentasType7(problem)),
                        Task.Factory.StartNew(() => GetPentasType8(problem)),
                        Task.Factory.StartNew(() => GetPentasType9(problem)),
                        Task.Factory.StartNew(() => GetPentasType10(problem)),
                        Task.Factory.StartNew(() => GetPentasType11(problem)),
                        Task.Factory.StartNew(() => GetPentasType12(problem)) */
                    };

            foreach (Task<KataminoDataSet.PentaDataTable> t in taskArray)
                table.Merge(t.Result);

            return table;
        }
    }
}
